package com.castle.fortress.admin.system.rest;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.castle.fortress.admin.core.annotation.CastleLog;
import com.castle.fortress.admin.core.constants.GlobalConstants;
import com.castle.fortress.admin.system.dto.ConfigOssDto;
import com.castle.fortress.admin.system.dto.OssPlatFormDto;
import com.castle.fortress.admin.system.entity.ConfigOssEntity;
import com.castle.fortress.admin.system.service.ConfigOssService;
import com.castle.fortress.common.entity.RespBody;
import com.castle.fortress.common.enums.OperationTypeEnum;
import com.castle.fortress.common.enums.OssEnum;
import com.castle.fortress.common.enums.YesNoEnum;
import com.castle.fortress.common.exception.BizException;
import com.castle.fortress.common.respcode.BizErrorCode;
import com.castle.fortress.common.respcode.GlobalRespCode;
import com.castle.fortress.common.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.util.Strings;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 文件传输控制器 控制器
 * @author castle
 */
@Api(tags = "文件传输控制器")
@RestController
@RequestMapping("/api/system/oss")
public class ApiOSSController {

    @Autowired
    private ConfigOssService configOssService;


    /**
     * 文件上传
     * @param file
     * @return
     */
    @CastleLog(operLocation="文件上传",operType= OperationTypeEnum.UPLOAD)
    @ApiOperation("文件上传")
    @PostMapping("/uploadFile")
    public RespBody<Map> uploadVideo(@RequestParam("file") MultipartFile file){
        if (file.isEmpty()) {
            throw new BizException(BizErrorCode.FT_UPLOAD_EMPTY_ERROR);
        }
        return configOssService.putFile(file);

    }
}
